SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.[DnnProduct_AutomaticStuckOrderHandling_StuckOrdersList]
AS
BEGIN
	SET NOCOUNT ON;

	DECLARE @SQLString NVARCHAR(1000)

	/* Build the SQL string once.*/
	SET @SQLString = N'WITH ItemRN AS (SELECT ROW_NUMBER() OVER(ORDER BY [Timestamp]) AS RowNum, LastOrderStatusesId, Name, PWVersion, LastOrderDateTime, LastOrderStatusCode, Action, Timestamp, StoreURL, StoreAdminURL, OrderNumber FROM [DnnProduct_AutomaticStuckOrderHandling_LastOrderStatuses]'

	SET @SQLString = @SQLString + N' ) SELECT LastOrderStatusesId, Name, PWVersion, LastOrderDateTime, LastOrderStatusCode, Action, Timestamp, StoreURL, StoreAdminURL, OrderNumber FROM ItemRN;'
	
	EXECUTE sp_executesql @SQLString
	
END
GO
